#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

#define MAXLINE      80

static void print_err(char *str) {
    if(str) perror(str);
    exit(-1);
}

void sig_alrm(int signo) {
    // do nothing, just return to interrupt the read
    printf("recv SIGALRM\n");
}

int main() {
    int n;
    char line[MAXLINE];

    if (signal(SIGALRM, sig_alrm) == SIG_ERR)
        print_err("signal(SIGALRM) erorr");

    alarm(5);
    if ((n = read(STDIN_FILENO, line, MAXLINE)) < 0)
        print_err("read error");
    alarm(0);

    write(STDOUT_FILENO, line, n);

    return 0;
}


